
import { mobxState } from "@/data";
import { toJS } from "mobx";


/**@description 根据pathname查找路由的激活menu activeMenu */
const getActiveMenu = (pathname) => {
    const routes = toJS(mobxState.routes);
    let activeMenu = null;

    const filter = (list, path) => {
        list.forEach(route => {
            if (route.path === path) {
                activeMenu = route.activeMenu;
                return;
            }
            if (route.children && route.children.length > 0) {
                filter(route.children, pathname);
            }
        })
    }

    filter(routes, pathname);
    return activeMenu;

}
export default getActiveMenu;